Skip to content

Conversation

@erenatas
Copy link
Contributor

@erenatas erenatas commented Nov 1, 2025

This PR

This change may be breaking to existing users

If both FLAGD_OFFLINE_FLAG_SOURCE_PATH and FLAGD_RESOLVER were set, FLAGD_OFFLINE_FLAG_SOURCE_PATH overrode the resolver type to File, ignoring FLAGD_RESOLVER.
What is done now:
FLAGD_RESOLVER takes precedence. If set, it is respected and FLAGD_OFFLINE_FLAG_SOURCE_PATH does not override the resolver type to File.

Add evaluation behavioral tests as well, did not require any change in implementation except error mapping with expectation

Related Issues

Improves #43

Notes

Follow-up Tasks

How to test

@gemini-code-assist
Copy link

Summary of Changes

Hello @erenatas, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request modernizes the project by updating to the Rust 2024 edition and bringing various dependencies to their latest versions. It introduces significant enhancements to the flagd provider, focusing on improved cache management and a more robust targeting evaluation system through an updated integration with datalogic-rs. The env-var provider also benefits from refined testing practices, ensuring greater stability and reliability across the board.

Highlights

  • Rust Edition and Dependency Updates: The project has been updated to Rust 2024 edition across multiple crates (main, env-var, flagd, flipt), along with a bump in the minimum supported Rust version (MSRV) for flagd. Numerous dependencies, including open-feature, async-trait, tokio, tonic, prost, datalogic-rs, and various testing utilities, have been upgraded to their latest versions.
  • Enhanced env-var Provider Testing: The env-var provider's example code and Cucumber tests have been refactored to use temp-env and test-with::runner! for safer and more isolated environment variable handling, preventing test pollution and ensuring reliable test execution.
  • flagd Provider Cache Management: The flagd provider's cache service now includes a purge method, and both FileResolver and InProcessResolver have been updated to clear their caches automatically when flag store updates are detected, ensuring data freshness.
  • Improved flagd Targeting Logic: The flagd provider's in-process targeting logic has been significantly refactored to integrate with the updated datalogic-rs library's Operator trait. This change modernizes the fractional and semver targeting implementations, improving context handling and evaluation.
  • Code Modernization and Test Reliability: The codebase now utilizes newer Rust syntax like if let Some(...) && let Some(...) for cleaner optional value unwrapping. Additionally, retry mechanism tests in flagd have been made more robust by using dynamic ports, and environment variable handling in gherkin_config_test.rs has been improved for better test isolation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@erenatas erenatas marked this pull request as draft November 1, 2025 10:59
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a number of significant improvements and fixes across the flagd and env-var crates. Key changes include upgrading to the Rust 2024 edition, updating numerous dependencies, and most notably, a major refactoring of the in-process targeting engine to use datalogic-rs v4. This refactoring has greatly improved the code's safety and clarity, especially in the fractional and semver targeting operators.

The behavioral tests have also been substantially improved for better conformance and reliability. The use of test-with and temp-env to manage environment variables in tests is a great change that addresses potential flakiness from parallel test execution.

I have one suggestion in crates/flagd/src/resolver/in_process/resolver/grpc.rs to improve code consistency in cache handling, bringing it in line with the FileResolver. Overall, this is a high-quality pull request with excellent changes.

erenatas and others added 8 commits November 3, 2025 08:59
@erenatas erenatas force-pushed the eren/behavioral-conformance-1 branch from 3142335 to f5c6a3b Compare November 3, 2025 08:02
@erenatas erenatas marked this pull request as ready for review November 3, 2025 08:05
@erenatas erenatas changed the title fix: flagd, behavioral tests conformance fix: flagd, behavioral tests conformance (evaluation and config) Nov 3, 2025
@beeme1mr beeme1mr changed the title fix: flagd, behavioral tests conformance (evaluation and config) fix!: flagd, behavioral tests conformance (evaluation and config) Nov 3, 2025
Signed-off-by: Eren Atas <[email protected]>
@erenatas erenatas requested a review from aepfli November 4, 2025 13:29
Copy link
Member

@beeme1mr beeme1mr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in the same boat as @aepfli. I don't know Rust well enough to be confident in my review but the change is relatively straightforward and looks okay to me.

@erenatas
Copy link
Contributor Author

erenatas commented Nov 4, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces significant improvements by fixing a configuration precedence issue and adding comprehensive behavioral tests for both configuration and evaluation. The changes make the provider more robust and conformant with specifications.

The new provider_id option is a good addition for identifying provider instances. The error mapping from gRPC status codes to OpenFeature error codes is a great enhancement for error handling consistency. The new evaluation test suite using testcontainers and Gherkin is particularly impressive and greatly increases confidence in the provider's correctness.

I have two main points of feedback:

  1. A potential discrepancy in the configuration test logic which seems to contradict the intended precedence rules.
  2. An opportunity to reduce code duplication in the new evaluation test suite.

Overall, this is a high-quality contribution. Please see my detailed comments.

Comment on lines 160 to 167
if let Some(source) = world.option_values.get("offlineFlagSourcePath") {
options.source_configuration = Some(source.clone());
if options.resolver_type != ResolverType::Rpc {
// For backwards compatibility: if offline path is set, switch to File resolver
// UNLESS resolver was explicitly set to "rpc" (in which case keep it as "rpc")
if !resolver_explicitly_set || options.resolver_type != ResolverType::Rpc {
options.resolver_type = ResolverType::File;
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The logic here for determining the resolver type seems to contradict the stated goal of the pull request and the implementation in FlagdOptions::default().

The PR description states: "FLAGD_RESOLVER takes precedence. If set, it is respected and FLAGD_OFFLINE_FLAG_SOURCE_PATH does not override the resolver type to File."

The logic in FlagdOptions::default() correctly implements this by only overriding to File if FLAGD_RESOLVER is not set. However, the logic in this test is if !resolver_explicitly_set || options.resolver_type != ResolverType::Rpc, which is equivalent to if !(resolver_explicitly_set && options.resolver_type == ResolverType::Rpc). This means that setting offlineFlagSourcePath will force the resolver to File unless the resolver was explicitly set to Rpc. For example, if the resolver was explicitly set to InProcess, this logic would override it to File, which seems incorrect according to the PR's goal.

If the goal is to give any explicitly set resolver precedence, the condition should be simplified. If the current logic is required to pass the behavioral tests, it might be worth adding a more detailed comment explaining this specific backward-compatibility rule.

Suggested change
if let Some(source) = world.option_values.get("offlineFlagSourcePath") {
options.source_configuration = Some(source.clone());
if options.resolver_type != ResolverType::Rpc {
// For backwards compatibility: if offline path is set, switch to File resolver
// UNLESS resolver was explicitly set to "rpc" (in which case keep it as "rpc")
if !resolver_explicitly_set || options.resolver_type != ResolverType::Rpc {
options.resolver_type = ResolverType::File;
}
}
if let Some(source) = world.option_values.get("offlineFlagSourcePath") {
options.source_configuration = Some(source.clone());
// For backwards compatibility: if offline path is set, switch to File resolver
// UNLESS resolver was explicitly set.
if !resolver_explicitly_set {
options.resolver_type = ResolverType::File;
}
}

Comment on lines +467 to +576
match world.flag_type.as_str() {
"Boolean" => {
let default_bool = world.default_value.to_lowercase() == "true";
let result = provider
.resolve_bool_value(&world.flag_key, &world.context)
.await;

match result {
Ok(details) => {
world.resolved_value = Some(details.value.to_string());
world.resolved_reason = details.reason.map(reason_to_string);
world.resolved_variant = details.variant;
world.resolved_error_code = None;
}
Err(err) => {
world.resolved_value = Some(default_bool.to_string());
world.resolved_reason = Some("ERROR".to_string());
world.resolved_error_code = Some(format!("{:?}", err.code));
}
}
}
"String" => {
let result = provider
.resolve_string_value(&world.flag_key, &world.context)
.await;

match result {
Ok(details) => {
world.resolved_value = Some(details.value.clone());
world.resolved_reason = details.reason.map(reason_to_string);
world.resolved_variant = details.variant;
world.resolved_error_code = None;
}
Err(err) => {
world.resolved_value = Some(world.default_value.clone());
world.resolved_reason = Some("ERROR".to_string());
world.resolved_error_code = Some(format!("{:?}", err.code));
}
}
}
"Integer" => {
let default_int = world.default_value.trim().parse::<i64>().unwrap_or(0);
let result = provider
.resolve_int_value(&world.flag_key, &world.context)
.await;

match result {
Ok(details) => {
world.resolved_value = Some(details.value.to_string());
world.resolved_reason = details.reason.map(reason_to_string);
world.resolved_variant = details.variant;
world.resolved_error_code = None;
}
Err(err) => {
world.resolved_value = Some(default_int.to_string());
world.resolved_reason = Some("ERROR".to_string());
world.resolved_error_code = Some(format!("{:?}", err.code));
}
}
}
"Float" => {
let default_float = world.default_value.trim().parse::<f64>().unwrap_or(0.0);
let result = provider
.resolve_float_value(&world.flag_key, &world.context)
.await;

match result {
Ok(details) => {
world.resolved_value = Some(details.value.to_string());
world.resolved_reason = details.reason.map(reason_to_string);
world.resolved_variant = details.variant;
world.resolved_error_code = None;
}
Err(err) => {
world.resolved_value = Some(default_float.to_string());
world.resolved_reason = Some("ERROR".to_string());
world.resolved_error_code = Some(format!("{:?}", err.code));
}
}
}
"Object" => {
let result = provider
.resolve_struct_value(&world.flag_key, &world.context)
.await;

match result {
Ok(details) => {
// Convert StructValue to JSON by converting fields
let json_obj: serde_json::Map<String, serde_json::Value> = details
.value
.fields
.iter()
.map(|(k, v)| (k.clone(), value_to_json(v)))
.collect();
let json_str =
serde_json::to_string(&json_obj).unwrap_or_else(|_| "{}".to_string());
world.resolved_value = Some(json_str);
world.resolved_reason = details.reason.map(reason_to_string);
world.resolved_variant = details.variant;
world.resolved_error_code = None;
}
Err(err) => {
world.resolved_value = Some(world.default_value.clone());
world.resolved_reason = Some("ERROR".to_string());
world.resolved_error_code = Some(format!("{:?}", err.code));
}
}
}
_ => panic!("Unknown flag type: {}", world.flag_type),
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's a significant amount of duplicated logic in the match statement for handling the results of different resolve_*_value calls. The Ok and Err arms are nearly identical for each flag type. This could be refactored to improve maintainability.

Consider extracting the logic for handling Ok(details) and Err(err) into helper functions. This would make the evaluate_flag_with_details function shorter and easier to read. Note that the Object type might require special handling due to its conversion to a JSON string.

For example, you could have helpers like:

fn handle_ok<T>(world: &mut EvaluationWorld, details: open_feature::ResolutionDetails<T>, value_str: String) {
    world.resolved_value = Some(value_str);
    world.resolved_reason = details.reason.map(reason_to_string);
    world.resolved_variant = details.variant;
    world.resolved_error_code = None;
}

fn handle_err<T: ToString>(world: &mut EvaluationWorld, err: open_feature::EvaluationError, default_value: T) {
    world.resolved_value = Some(default_value.to_string());
    world.resolved_reason = Some("ERROR".to_string());
    world.resolved_error_code = Some(format!("{:?}", err.code));
}

This would help reduce the boilerplate in each match arm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants